﻿using System.IO;
using Patriq.Common.Environment;

namespace Patriq.Msmq.Router.Core
{
    public interface IScriptsReader
    {
        string DataScript { get; }
        string LogicScript { get; }
    }

    public class FileScriptsReader : IScriptsReader
    {
        private readonly string dataScript;
        private readonly string logicScript;

        public FileScriptsReader(IEnvironment environment, string logicScriptFileName, string dataScriptFileName)
            : this(environment.BasePath, logicScriptFileName, dataScriptFileName)
        {
        }

        public FileScriptsReader(string basePath, string logicScriptFileName, string dataScriptFileName)
            : this(Path.Combine(basePath, dataScriptFileName), Path.Combine(basePath, logicScriptFileName))
        {
        }

        public FileScriptsReader(string fullDataScriptFilePath, string fullLogicScriptFilePath)
        {
            dataScript = File.ReadAllText(fullDataScriptFilePath);
            logicScript = File.ReadAllText(fullLogicScriptFilePath);
        }

        public string DataScript
        {
            get { return dataScript; }
        }

        public string LogicScript
        {
            get { return logicScript; }
        }
    }
}